#include<bits/stdc++.h>
using namespace std;
const int N = 2 * 114514;
int t,n,ans;
int a[N],p[N];
void dfs(int dep){
    if(dep > n){
        int cnt1 = 0;
        int cnt2 = 0;
        int sum = 0;
        for(int i = 1;i <= n;i ++ ){
            if(p[i] == 1){
                if(a[i] == cnt1) sum += a[i];
                cnt1 = a[i];
            }
            else{
                if(a[i] == cnt2) sum += a[i];
                cnt2 = a[i];
            }
        }
        ans = max(ans,sum);
        return;
    }
    p[dep] = 1;
    dfs(dep + 1);
    p[dep] = 2;
    dfs(dep + 1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    while(t--){
        ans = 0;
        cin >> n;
        for(int i = 1;i <= n;i ++ ){
            cin >> a[i];
        }
        dfs(1);
        cout << ans << endl;
    }
}